<?php
namespace app\admin\logic;
use app\admin\validate\ModularDict as ModularDictValidate;

class ModularDictLogic extends BaseLogic {

    /**
     * 获取模块字典查询条件
     * @return array
     */
    public function get_search_modular_dict_maps(){
        $maps = [];
        return $maps;
    }

    /**
     * 检查新增模块字典规则
     * @param $params
     * @return mixed
     */
    public function check_add_modular_dict_rule($params){
        $validate = new ModularDictValidate();
        $r = $validate->scene('add')->check($params);
        if(!$r){
            return $this->get_response(0,$validate->getError());
        }

        $maps = [];
        $maps[] = ['name','=',trim($params['name'])];
        $md_detail = model('modular_dict')->get_detail($maps,'id');
        if(!empty($md_detail)){
            return $this->get_response(0,'该模块已存在');
        }
        return $this->get_response(1,'OK');
    }

    /**
     * 检查修改模块字典规则
     * @param $params
     * @return mixed
     */
    public function check_save_modular_dict_rule($params){
        $validate = new ModularDictValidate();
        $r = $validate->scene('edit')->check($params);
        if(!$r){
            return $this->get_response(0,$validate->getError());
        }

        $maps = [];
        $maps[] = ['id','=',$params['mdid']];
        $md_detail = model('modular_dict')->get_detail($maps,'id');
        if(empty($md_detail)){
            return $this->get_response(0,'该模块不存在');
        }

        $maps = [];
        $maps[] = ['id','<>',$params['mdid']];
        $maps[] = ['name','=',trim($params['name'])];
        $detail = model('modular_dict')->get_detail($maps,'id');
        if(!empty($detail)){
            return $this->get_response(0,'该模块已存在');
        }

        $data['md_detail'] = $md_detail;
        return $this->get_response(1,'OK',$data);
    }

    /**
     * 获取模块字典公用查询条件
     * @return array
     */
    public function get_search_public_modular_dict_maps(){
        $maps = [];
        return $maps;
    }
}